﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="email_wbyj_edit.aspx.cs"
    Inherits="Ccit.OA.Email.email_wbyj_edit" %>

<%@ Register TagPrefix="ccit" Namespace="Ccit.ServerControls" Assembly="Ccit.ServerControls.ActionForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>个人签名</title>

    <script language="javascript" src="../script/jquery.js" type="text/javascript"></script>

    <script language="javascript" src="../script/jbase64.js" type="text/javascript"></script>

    <script language="javascript" src="../script/jsonlib.js" type="text/javascript"></script>

    <script language="javascript" src="../script/StringClass_Ext.js" type="text/javascript"></script>

    <script language="javascript">
         function doSave()
         {
            if(CheckVal() == true)
            {
                var jsonStr = jsonObj();
                PageMethods.Save(jsonStr,ClientCallBack); 
            }
         }
         
         function CheckVal()
         {
            if($get("txtAccountName").value == "")
            {
                alert("账号名称不允许为空!");
                document.getElementById("txtAccountName").focus(); 
                return false;
            }
            if($get("txtAddress").value == "")
            {
                alert("电子邮件地址不允许为空!");
                document.getElementById("txtAddress").focus(); 
                return false;
            }
            if($get("txtSMTP").value == "" || $get("txtSMTPPort").value == "")
            {
                alert("SMTP服务器或对应端口号填写不完整!");
                if($get("txtSMTP").value == "")
                {
                   document.getElementById("txtSMTP").focus(); 
                }
                else
                {
                   document.getElementById("txtSMTPPort").focus(); 
                }
                return false;
            }
            if(document.getElementById("cbMR").checked == true)
            {
                if(document.getElementById("rbYZXX").checked == true)
                {
                     if($get("txtZH").value == "" || $get("txtPass").value == "")
                     {
                        alert("验证信息填写不完整");
                        if($get("txtZH").value == "")
                        {
                           document.getElementById("txtZH").focus(); 
                        }
                        else
                        {
                           document.getElementById("txtPass").focus(); 
                        }
                        return false;
                     }
                }
            }
            if($get("txtpop3").value == "" || $get("txtpopPort").value == "")
            {
                alert("接收邮件服务器(POP3) 信息填写不完整!");
                if($get("txtpop3").value == "")
                {
                   document.getElementById("txtpop3").focus(); 
                }
                else
                {
                   document.getElementById("txtpopPort").focus(); 
                }
                return false;
            }
            
            if($get("txtZHPOP3").value == "" || $get("txtpassPOP3").value == "")
            {
                alert("POP3登录名称或密码不允许为空!");
                if(document.getElementById("txtZHPOP3").value == "")
                {
                    document.getElementById("txtZHPOP3").focus();
                }
                else{
                    document.getElementById("txtpassPOP3").focus();
                }
                return false;
            }
            return true;
         }
         
         function CliNumber(ContantName)
         {
            if(isNaN(document.getElementById(ContantName).value))
            {
                document.getElementById(ContantName).value = "";
                alert("只允许输入数字!");
            }
         }

        
        
         function ClientCallBack(vResult) {
            eval("var resultObj=" + vResult);
            var operType = resultObj.operType;
            var resultSign = resultObj.resultSign;
            switch (operType) {
                case "Del": 
                    if (resultSign == "0") {
                        alert("删除失败!");
                    }
                    else {
                            parent.frames[0].document.getElementById("_hidDelEmlId").value = resultObj.resultId; 
                            parent.frames[0].document.all.btnDelTrigger.click(); 
                            parent.frames[1].location.href = "email_wbyj_edit.aspx"
                    }
                    break;
                case "insert":
                     if (resultSign == "0") {
                        alert("保存失败!");
                    }
                    else {                        
                          //实例化MsEmailAccount消息对象
                        var MsEmailAccount = {};
                        MsEmailAccount.Id= resultObj.resultId;        
                        MsEmailAccount.Title = resultObj.resultName;       //标题                      
                       
                        var jsonExpr=JSON.stringify(MsEmailAccount,function(key,value){return value;});
                        parent.frames[0].document.getElementById("_hidNewEmlObject").value = jsonExpr;  //新增 
                        parent.frames[0].document.getElementById("_hidAddNewEml").value = "0";  //新增 
                        parent.frames[0].document.all.btnTrigger.click(); 
                        parent.frames[1].location.href = "email_wbyj_edit.aspx"
                        
                    }
                break;
                case "update":
                     if (resultSign == "0") {
                            alert("更新失败!");
                        }
                        else {
                        
                        var MsEmailAccount = {};
                        MsEmailAccount.Id= resultObj.resultId;        
                        MsEmailAccount.Title = resultObj.resultName;       //标题                      
                       
                        var jsonExpr=JSON.stringify(MsEmailAccount,function(key,value){return value;});
                        parent.frames[0].document.getElementById("_hidNewEmlObject").value = jsonExpr;  //新增 
                        parent.frames[0].document.getElementById("_hidAddNewEml").value = "1";  //新增 
                        parent.frames[0].document.all.btnTrigger.click(); 
                        //parent.frames[1].location.href = "email_wbyj_edit.aspx"
                        alert("更新成功!");
                     }
                break;
                }
              }
              
              function cbMR_Click()
              {
                var tdSFYZ = document.getElementById("tdSFYZ");
                var cbMR = document.getElementById("cbMR");
                
                if(cbMR.checked == true)
                {
                    tdSFYZ.style.display = "block";
                }
                else{
                    tdSFYZ.style.display = "none";
                }
                
              }
              
             
        function jsonObj() //返回序列化后的字符串
        {
            var receLogo = "0";
            var delWebLogo = "0";
            var serverLogo = "1";
            var sendemlyzLogo = "0"; 
            var changesLogo = "1";//自动接收
            if(document.getElementById("rbysDel").checked == true)
            {
                delWebLogo = "1";   //接收后删除远程邮件
            } 
            if(document.getElementById("rbYZXX").checked == true)
            {
                serverLogo = "0";   //使用与接收邮件邮件服务器相同设置标志  0不同 / 1同
            }
            if(document.getElementById("cbMR").checked == true)
            {
                sendemlyzLogo = "1";   //发送邮件服务器需要验证标志  0不需要 / 1需要
            }
            if(document.getElementById("rbysDef").checked == true)
            {
                changesLogo = "1";      //是否为默认发送邮箱
            }
            var MsAccount ={};
                MsAccount.Id = $get("hidId").value;
                MsAccount.userId = $get("hidUserId").value;
                MsAccount.accountName = $get("txtAccountName").value;
                MsAccount.userName = $get("hidName").value;
                MsAccount.address = $get("txtAddress").value;
                MsAccount.order =$get("txtOrder").value;
                MsAccount.logoYN = "1";
                MsAccount.receivePOP3 = $get("txtpop3").value;
                MsAccount.pop3Port = $get("txtpopPort").value;
                MsAccount.pop3LogName = $get("txtZHPOP3").value;
                MsAccount.pop3Pass =  $get("txtpassPOP3").value;
                MsAccount.receLogo =  receLogo;
                MsAccount.delWebLogo =  delWebLogo;
                MsAccount.receiveFolder =  document.getElementById("ddFolder").options[document.getElementById("ddFolder").selectedIndex].value;
                MsAccount.receiveSMTP =  $get("txtSMTP").value;
                MsAccount.smtpPort =  $get("txtSMTPPort").value;
                MsAccount.serverLogo =  serverLogo;
                //使用与POP3服务器相同的信息 
                if(document.getElementById("rbPOP").checked == true)
                {
                    MsAccount.smtpLogName = $get("txtZHPOP3").value;
                    MsAccount.smtpPass = $get("txtpassPOP3").value;
                }
                else
                {
                    MsAccount.smtpLogName =  $get("txtZH").value;
                    MsAccount.smtpPass =  $get("txtpass").value;
                }
                MsAccount.sendemlyzLogo =  sendemlyzLogo;
                MsAccount.systemLogo =  "0";    //0非系统   1系统
                MsAccount.changesLogo =  changesLogo;   //0默认发送   1非默认发送
                
                
                MsAccount.agencId =$get("hidJG").value;
                MsAccount.deptId = $get("hidYGBM").value;
                MsAccount.jobId = $get("hidYGZW").value;
                MsAccount.levelId = $get("hidYGJB").value;
                MsAccount.cjuserId = $get("hidUserId").value;
                MsAccount.cjdatetime =  $get("hidTime").value;
      
                var jsonStr = JSON.stringify(MsAccount,function(key,value){return value;});  
                return jsonStr;
        }
        
      
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
    <input type="hidden" id="hidId" runat="server" />
    <input type="hidden" id="hidUserId" runat="server" />
    <input type="hidden" id="hidYGJB" runat="server" />
    <input type="hidden" id="hidYGBM" runat="server" />
    <input type="hidden" id="hidYGZW" runat="server" />
    <input type="hidden" id="hidJG" runat="server" />
    <input type="hidden" id="hidTime" runat="server" />
    <input type="hidden" id="hidName" runat="server" />
    <table class="tableborder" cellspacing="0" cellpadding="0" width="98%" align="center">
        <tr height="60">
            <td class="pformleft" align="right">
                账户名称:
            </td>
            <td class="pformright" align="left" width="80%">
                <asp:TextBox CssClass="input" ID="txtAccountName" Width="100%" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="pformleft" align="right" valign="top">
                电子邮件地址:
            </td>
            <td class="pformright" align="left" width="80%">
                <asp:TextBox CssClass="input" ID="txtAddress" Width="100%" runat="server"></asp:TextBox>
            </td>
        </tr
        
         <tr>
            <td class="pformleft" align="right" valign="top">
                <nobr>接收邮件服务器(POP3):<nobr>
            </td>
            <td class="pformright" align="left" width="80%">
               <div style="float:left;"><div style="float:left;"><asp:TextBox CssClass="input"  ID="txtpop3" Width="300px" runat="server"></asp:TextBox></div><div style="float:right;">端口 <asp:TextBox CssClass="input" Text="110"  runat="server" Width="70px" ID="txtpopPort"></asp:TextBox></div></div>
            </td>
        </tr>
        <tr>
            <td class="pformleft" >&nbsp;</td>
            <td class="pformright" width="80%"><div style="float:left;"><div style="float:left;">
                POP3服务器验证信息 : 账号&nbsp;<asp:TextBox CssClass="input" runat="server" 
                    Width="144px" ID="txtZHPOP3"></asp:TextBox></div><div style="float:right;">密码 <asp:TextBox TextMode="Password" runat="server" CssClass="input" Width="70px" 
                    ID="txtpassPOP3"></asp:TextBox></div></div>
            </td>
        </tr>
        
         <tr>
            <td class="pformleft" align="right" valign="top">
                <nobr>发送邮件服务器(SMTP):<nobr>
            </td>
            <td class="pformright" align="left" width="80%">
               <div style="float:left;"><div style="float:left;"><asp:TextBox CssClass="input"  ID="txtSMTP" Width="300px" runat="server"></asp:TextBox></div><div style="float:right;">端口 <asp:TextBox CssClass="input" runat="server"   Text="25" Width="70" ID="txtSMTPPort"></asp:TextBox></div></div>
            </td>
        </tr>
        <tr>
            <td class="pformleft">&nbsp;
            </td>
            <td align="left" class="pformright">
                <input onclick="cbMR_Click()" type="checkbox" id="cbMR" value="1" runat="server" />SMTP服务器需要身份验证
            </td>
        </tr>
        <tr runat="server" id="tdSFYZ" style="display: none">
            <td class="pformleft">&nbsp;
            </td>
            <td align="left" class="pformright">
                <table border="0" width="100%">
                    <tr>
                        <td>
                            <asp:RadioButton Checked="true" ID="rbPOP" runat="server" GroupName="YZXX" />使用与POP3服务器相同的信息
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:RadioButton ID="rbYZXX" runat="server" GroupName="YZXX" />验证信息 : 账号&nbsp;<asp:TextBox CssClass="input" runat="server" Width="180px" ID="txtZH"></asp:TextBox>&nbsp;&nbsp;&nbsp;密码 <asp:TextBox runat="server" TextMode="Password" CssClass="input" Width="68px" ID="txtPass"></asp:TextBox>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>

        <tr>
            <td class="pformleft" align="right" valign="top">
                <nobr>收件后是否删除远程邮件:<nobr>
            </td>
            <td class="pformright" align="left" width="80%">
                 <div style="float:left;"><div style="float:left;">
                 <asp:RadioButton ID="rbysDel" Checked="true" runat="server" GroupName="DelYesorNo" Text="是" />
                 <asp:RadioButton ID="rbnoDel" runat="server" GroupName="DelYesorNo" 
                            Text="否" /></div><div style="float:right;">接收邮件夹 <asp:DropDownList runat="server" ID="ddFolder"></asp:DropDownList></div></div>
            </td>
        </tr>
        <tr>
            <td class="pformleft" align="right" valign="top">
                <nobr>是否为默认发送邮箱:<nobr>
            </td>
            <td class="pformright" align="left" width="80%">
                <div style="float:left;"><div style="float:left;">
                <asp:RadioButton ID="rbysDef" Checked="true" runat="server" GroupName="defalutYesorNo" Text="是" />
                <asp:RadioButton ID="rbnoDef" runat="server" GroupName="defalutYesorNo" 
                            Text="否" /></div><div style="float:right;">邮箱排列序号 <asp:TextBox CssClass="input" runat="server" Width="70px" ID="txtOrder"></asp:TextBox></div></div>
            </td>
        </tr>
        <tr align="center">
            <td class="pformstrip" colspan="2" align="center" valign="middle">
                <input type="button" class="button" value="保 存" onclick="doSave();" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
